package com.nbsaas.boot.cms.rest.convert;

import com.nbsaas.boot.cms.data.entity.News;
import com.nbsaas.boot.cms.api.domain.response.NewsResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
/**
* 新闻-实体对象转化成响应对象
*/

public class NewsResponseConvert  implements Converter<NewsResponse,News> {

    @Override
    public NewsResponse convert(News source) {
        NewsResponse  result = new  NewsResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }

                    try {
                        if(source.getCreator()!=null){
                            result.setCreatorName(source.getCreator().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getNewsCatalog()!=null){
                            result.setNewsCatalogName(source.getNewsCatalog().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getNewsCatalog()!=null){
                        result.setNewsCatalog(source.getNewsCatalog().getId());
                    }
                    if(source.getStoreState()!=null){
                        result.setStoreStateName(String.valueOf(source.getStoreState()));
                    }
        return result;
    }

}

